package it.polimi.traveldream.beans;

import it.polimi.traveldream.dto.TransportDTO;
import it.polimi.traveldream.ejb.ProductManager;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name = "transportBean")
@RequestScoped
public class TransportBean {

	@EJB
	private ProductManager productManager;

	private TransportDTO transport;

	public TransportBean() {
		this.transport = new TransportDTO();
	}

	public TransportDTO getTransport() {
		return this.transport;
	}

	public void setTransport(TransportDTO transport) {
		this.transport = transport;
	}

	public String save() {
		this.productManager.save(this.transport);
		return "/employee/products/list?faces-redirect=true";
	}

	public List<TransportDTO> getTransports() {
		return this.productManager.getTransports();
	}

	public List<TransportDTO> getFiltered(String origin, String destination) {
		return this.productManager.getFiltered(origin, destination);
	}

	public List<TransportDTO> getFromOrigin(String origin) {
		return this.productManager.getFromOrigin(origin);
	}

	public List<TransportDTO> getToDestination(String destination) {
		return this.productManager.getToDestination(destination);
	}

	public String removeTransport(TransportDTO t) {
		this.productManager.removeTransport(t);
		return "?faces-redirect=true";
	}
}
